NAME=checkers
MAJOR_VERSION=0.1
MINOR_VERSION=0
RELEASE_TAG=
PACKAGE_NAME=${NAME}-${MAJOR_VERSION}.${MINOR_VERSION}${RELEASE_TAG}

PYTHON="/usr/bin/python"
TMPDIR=~/tmp

CURDIR=~/src/checkers
SRC=~/src
BASE_DIR=${CURDIR}/..
PYTHONPATH=${BASE_DIR}
PACKAGES=checkers
TEST_SWITCHES=-vup
TEST_PROFILE=-vupP
TEST_DEBUG=-vvpD

RM=rm -f
RMRF=rm -rf
FIND=find
XARGS=xargs
CD=cd
LN=ln -sfn
CP=cp
TAR=tar
MKDIR=mkdir -p

.PHONY : clean test reindent reindent_clean sdist
.PHONY : default

# default:     The default step (invoked when make is called without a target)
default: clean test

clean :
	find . \( -name '*~' -o -name '*.py[co]' -o -name '*.bak' \) -exec rm {} \; -print

dist_clean: clean
	rm -rf dist; rm -rf build; rm -rf MANIFEST

reindent :
	~/src/reindent.py -r -v .

test :
	export PYTHONPATH=${PYTHONPATH}; \
	cd ${CURDIR} && ${PYTHON} ${SRC}/test.py --all ${TEST_SWITCHES} --libdir=.

test_profile :
	export PYTHONPATH=${PYTHONPATH}; \
	cd ${CURDIR} && ${PYTHON} ${SRC}/test.py --all ${TEST_PROFILE} --libdir=. checkers play_game

demo1 :
	export PYTHONPATH=${PYTHONPATH}; \
	cd ${CURDIR} && ${PYTHON} scripts/checkers_game.py -1 alpha-beta -2 file -d 2 -f ~/.checkers.txt

demo2 :
	export PYTHONPATH=${PYTHONPATH}; \
	cd ${CURDIR} && ${PYTHON} scripts/checkers_game.py -2 alpha-beta -1 file -d 2 -f ~/.checkers.txt

demo3 :
	export PYTHONPATH=${PYTHONPATH}; \
	cd ${CURDIR} && ${PYTHON} scripts/checkers_game.py -2 query -1 file -f ~/.checkers.txt

# sdist:       Create a source distribution file (implies clean).
#
sdist: reindent clean
	${PYTHON} ${CURDIR}/setup.py sdist

# sdist_tgz:   Create a tgz archive file as a source distribution.
#
sdist_tgz:
	echo -n "${MAJOR_VERSION}.${MINOR_VERSION}${RELEASE_TAG}" >\
          ${CURDIR}/version.txt
	${MKDIR} ${TMPDIR}/${PACKAGE_NAME}
	${CD} ${TMPDIR}/${PACKAGE_NAME} && \
          for package in ${PACKAGES}; do ${LN} ${BASE_DIR}/$$package .; done && \
          ${CD} ${TMPDIR} && ${TAR} czfh ${BASE_DIR}/${PACKAGE_NAME}.tgz ${PACKAGE_NAME} \
           --exclude=${PACKAGE_NAME}.tgz\
           --exclude=CVS \
           --exclude=.cvsignore \
           --exclude=makefile \
           --exclude=Makefile \
           --exclude=*.pyc \
           --exclude=TAGS \
           --exclude=*~ \
           --exclude=.#*
	${RMRF} ${TMPDIR}/${PACKAGE_NAME}
